package com.rustic.server.dto.user;

import cn.hutool.core.text.CharSequenceUtil;
import cn.xy.commons.exception.JzRuntimeException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotEmpty;

/**
 *  @author xy
 */
@Data
public class CaptchaLoginDTO {

    @NotEmpty(message = "手机号/邮箱不能为空")
    @ApiModelProperty(value = "手机号/邮箱", dataType = "String", required = true)
    private String account;

    @Length(min = 4, message = "请输入验证码")
    @ApiModelProperty(value = "验证码", dataType = "String")
    private String captcha;

    @ApiModelProperty(value = "密码", dataType = "String", required = true)
    private String password;

    @ApiModelProperty(value = "手机区号", dataType = "int")
    private Integer nationalityId;

    public void checkPassword() {
        if (CharSequenceUtil.isEmpty(password)) {
            throw new JzRuntimeException("密码不能为空");
        }
        if (password.length() < 6 || password.length() > 20) {
            throw new JzRuntimeException("密码长度为6-20位");
        }
    }
}
